package com.inossem.warehousestorage_inossem.activity.in_storage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.base.BaseActivity;
import com.inossem.warehousestorage_inossem.activity.in_storage.chuangyou.CYInStorageProductionListActivity;
import com.inossem.warehousestorage_inossem.activity.in_storage.chuangyou.CYInStorageShoppingListActivity;
import com.inossem.warehousestorage_inossem.activity.in_storage.extra.InStorageExtra;
import com.inossem.warehousestorage_inossem.activity.up_frame.UpFrame_ManageActivity;
import com.inossem.warehousestorage_inossem.utils.ActivityUtils;
import com.zhy.android.percent.support.PercentRelativeLayout;

public class InStorageManageActivity extends BaseActivity {

    private TextView title;

    private PercentRelativeLayout receiveInStorage, freeInStorage, otherInStorage, tenderInStorage , allocatingInStorage;

    private boolean mFlag = false;

    @Override
    protected void onCreateImpl(Bundle savedInstanceState) {
        setContentView(R.layout.activity_in_storage_manage);
        initView(InStorageManageActivity.this);
    }

    @Override
    protected void onResumeImpl() {
        initData(InStorageManageActivity.this);
    }

    private void initView(Activity activity) {
        title = (TextView) activity.findViewById(R.id.headerTitle);
        receiveInStorage = (PercentRelativeLayout) activity.findViewById(R.id.receiveInStorage);
        freeInStorage = (PercentRelativeLayout) activity.findViewById(R.id.freeInStorage);
        otherInStorage = (PercentRelativeLayout) activity.findViewById(R.id.otherInStorage);
        tenderInStorage = (PercentRelativeLayout) activity.findViewById(R.id.tenderInStorage);
        allocatingInStorage = (PercentRelativeLayout) activity.findViewById(R.id.allocatingInStorage);
    }

    private void initData(Activity activity) {
        title.setText(activity.getResources().getString(R.string.activity_in_storage_manage_title));
        ActivityUtils.initBackAndFunction(activity, R.string.activity_main_title_short, new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                finish();
            }
        });
        getExtra(activity);
        if (mFlag) {
            Intent intent = new Intent(activity, UpFrame_ManageActivity.class);
            startActivity(intent);
            finish();
        } else {
            receiveInStorage.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    Intent intent = new Intent(InStorageManageActivity.this, CYInStorageProductionListActivity.class);
                    startActivity(intent);
                }
            });
            freeInStorage.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    Intent intent = new Intent(InStorageManageActivity.this, CYInStorageShoppingListActivity.class);
                    startActivity(intent);
                }
            });
            otherInStorage.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    Intent intent = new Intent(InStorageManageActivity.this, InStorageOtherIndexActivity.class);
                    startActivity(intent);
                }
            });
            tenderInStorage.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    Intent intent = new Intent(InStorageManageActivity.this, InStorageTenderListActivity.class);
                    startActivity(intent);
                }
            });
            allocatingInStorage.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    Intent intent = new Intent(InStorageManageActivity.this, InStorageAllocatingListActivity.class);
                    startActivity(intent);
                }
            });
        }
    }

    private void getExtra(Activity activity) {
        mFlag = activity.getIntent().getBooleanExtra(InStorageExtra.FLAG, false);
    }

}
